Animated_Actions = {}

function Animated_Actions.AllAnimsOn()
	if(AnimatedActionsGUI.isActiveButtonToggledOn() == false) then
		VehicleRepairAction = true
		VehicleCleanAction = true
		VehicleRefuelAction = true
		PlayerSitGround = true
		PlayerSitBench = true
	elseif(AnimatedActionsGUI.isActiveButtonToggledOn()) then
		VehicleRepairAction = false
		VehicleCleanAction = false
		VehicleRefuelAction = false
		PlayerSitGround = false
		PlayerSitBench = false
	end
end

function Animated_Actions.RefuelCar()
	if(AnimatedActionsGUI.isActiveButtonToggledOn() == false) then
		VehicleRefuelAction = true	
	elseif(AnimatedActionsGUI.isActiveButtonToggledOn()) then
		VehicleRefuelAction = false
	end
end

function Animated_Actions.RepairCar()
	if(AnimatedActionsGUI.isActiveButtonToggledOn() == false) then
		VehicleRepairAction = true		
	elseif(AnimatedActionsGUI.isActiveButtonToggledOn()) then
		VehicleRepairAction = false	
	end
end

function Animated_Actions.CleanCar()
	if(AnimatedActionsGUI.isActiveButtonToggledOn() == false) then
		VehicleCleanAction = true		
	elseif(AnimatedActionsGUI.isActiveButtonToggledOn()) then
		VehicleCleanAction = false	
	end
end

function Animated_Actions.SitGround()
	if(AnimatedActionsGUI.isActiveButtonToggledOn() == false) then
		PlayerSitGround = true	
	elseif(AnimatedActionsGUI.isActiveButtonToggledOn()) then
		PlayerSitGround = false
	end
end

function Animated_Actions.SitBench()
	if(AnimatedActionsGUI.isActiveButtonToggledOn() == false) then
		PlayerSitBench = true	
	elseif(AnimatedActionsGUI.isActiveButtonToggledOn()) then
		PlayerSitBench = false
	end
end





-- AnimatedActions tick
function Animated_Actions.tick()


	if AnimTransferHelper then
		FinishedTimeAnim = natives.TIME.GET_CLOCK_MINUTES()
		if FinishedTimeAnim-1 > SavedStartingTime then
			AnimTransitionHelper = true
			WhatDirectionIsPlayer = natives.ENTITY.GET_ENTITY_HEADING(plyPed)
			natives.ENTITY.SET_ENTITY_HEADING(plyPed, WhatDirectionIsPlayer+180)
			natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@BASE")
			if natives.STREAMING.HAS_ANIM_DICT_LOADED("AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@BASE") == true then
				natives.AI.TASK_PLAY_ANIM(plyPed, "AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@BASE", "base", -8, -8, -1, 1, 0, false, false, true)
				Player_Position_Get = Player(ply):GetPosition()
				local WrenchRepairHash = natives.GAMEPLAY.GET_HASH_KEY("prop_tool_wrench")
				natives.STREAMING.REQUEST_MODEL(WrenchRepairHash)
				local WrenchRepair = natives.OBJECT.CREATE_OBJECT(WrenchRepairHash, 0, 0, 0, true, true, false)
				natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(WrenchRepair, plyPed, 0x49d9, -0.58, -0.10, -0.95, 90.0, 0.0, 0.0, false, false, false, false, 2, true)
				if SpawnedWrenchRepair == nil then SpawnedWrenchRepair = {} end
				table.insert(SpawnedWrenchRepair, WrenchRepair)
				local ToolboxRepairHash = natives.GAMEPLAY.GET_HASH_KEY("prop_tool_box_02")
				natives.STREAMING.REQUEST_MODEL(ToolboxRepairHash)
				local ToolboxRepair = natives.OBJECT.CREATE_OBJECT(ToolboxRepairHash, 0, 0, 0, true, true, false)
				natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(ToolboxRepair, plyPed, 0x49d9, 0.58, -0.10, -0.99, 0.0, 0.0, 15.0, false, false, false, false, 2, true)
				if SpawnedToolboxRepair == nil then SpawnedToolboxRepair = {} end
				table.insert(SpawnedToolboxRepair, ToolboxRepair)
				local ScrewdriverRepairHash = natives.GAMEPLAY.GET_HASH_KEY("prop_tool_screwdvr01")
				natives.STREAMING.REQUEST_MODEL(ScrewdriverRepairHash)
				local ScrewdriverRepair = natives.OBJECT.CREATE_OBJECT(ScrewdriverRepairHash, 0, 0, 0, true, true, false)
				natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(ScrewdriverRepair, plyPed, 0x49d9, 0.58, -0.30, -0.99, 0.0, 90.0, 15.0, false, false, false, false, 2, true)
				if SpawnedScrewdriverRepair == nil then SpawnedScrewdriverRepair = {} end
				table.insert(SpawnedScrewdriverRepair, ScrewdriverRepair)
				AnimCheck = true
				AnimTransferHelper = false
				AnimReady = true
			end
		end
	end
	
	if AnimTransitionHelper then
		AnimTransitionHelper = false
	end

	if VehicleCleanAction then
		if IsKeyDown(CleaningVehicleStartKey) then
			natives.WEAPON.GIVE_DELAYED_WEAPON_TO_PED(plyPed, natives.GAMEPLAY.GET_HASH_KEY("WEAPON_PROXMINE"), 1, true)
			natives.WEAPON.SET_CURRENT_PED_WEAPON(plyPed, natives.GAMEPLAY.GET_HASH_KEY("WEAPON_PROXMINE"), true)
			natives.AI.CLEAR_PED_TASKS_IMMEDIATELY(plyPed)
			natives.STREAMING.REQUEST_ANIM_DICT("timetable@floyd@clean_kitchen@base")
			if natives.STREAMING.HAS_ANIM_DICT_LOADED("timetable@floyd@clean_kitchen@base") == true then
				natives.AI.TASK_PLAY_ANIM(plyPed, "timetable@floyd@clean_kitchen@base", "base", 8, -8, -1, 1, 0, false, false, true)
				AnimCheck2 = true
				Player_Position_Get = Player(ply):GetPosition()
				local BucketCleaningHash = natives.GAMEPLAY.GET_HASH_KEY("prop_bucket_02a")
				natives.STREAMING.REQUEST_MODEL(BucketCleaningHash)
				local BucketCleaning = natives.OBJECT.CREATE_OBJECT(BucketCleaningHash, 0, 0, 0, true, true, false)
				natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(BucketCleaning, plyPed, 0x49d9, 0.58, -0.30, -0.99, 0.0, 0.0, 15.0, false, false, false, false, 2, true)
				if SpawnedBucketCleaning == nil then SpawnedBucketCleaning = {} end
				table.insert(SpawnedBucketCleaning, BucketCleaning)
			end
		end
		
		if IsKeyDown(CleaningVehicleStopKey) then
			if AnimCheck2 == true then
				natives.STREAMING.REQUEST_ANIM_DICT("TIMETABLE@FLOYD@CLEAN_KITCHEN@IDLE_A")
				if natives.STREAMING.HAS_ANIM_DICT_LOADED("TIMETABLE@FLOYD@CLEAN_KITCHEN@IDLE_A") == true then
					natives.AI.TASK_PLAY_ANIM(plyPed, "TIMETABLE@FLOYD@CLEAN_KITCHEN@IDLE_A", "idle_a", 8, -8, 5100, 0, 0, false, false, true)
					local vehz = natives.PLAYER.GET_PLAYERS_LAST_VEHICLE()
					CurrentDirtLevel = CurrentDirtLevel-5
					natives.VEHICLE.SET_VEHICLE_DIRT_LEVEL(vehz, CurrentDirtLevel-5)
					gui.NotifyAboveMap("Vehicle Fully Cleaned", 1000)
					AnimCheck2 = false	
					if SpawnedBucketCleaning ~= nil then
						for k,v in pairs(SpawnedBucketCleaning) do
							c_CBucket = CMemoryBlock(4)
							c_CBucket:WriteDWORD32(0, v)
							natives.ENTITY.DELETE_ENTITY(c_CBucket) 
							c_CBucket:Release()
						end
						SpawnedBucketCleaning = nil
					end						
				end
			end
		end
	end	
		
		
		
		
		
		
	if VehicleRefuelAction then
		if IsKeyDown(RefuelStanceKey) then
			natives.AI.CLEAR_PED_TASKS_IMMEDIATELY(plyPed)
			natives.STREAMING.REQUEST_ANIM_DICT("TIMETABLE@GARDENER@FILLING_CAN")
			if natives.STREAMING.HAS_ANIM_DICT_LOADED("TIMETABLE@GARDENER@FILLING_CAN") == true then
				natives.AI.TASK_PLAY_ANIM(plyPed, "TIMETABLE@GARDENER@FILLING_CAN", "gar_ig_5_filling_can", 8, -8, -1, 1, 0, false, false, true)
				AnimCheck3 = true
				Player_Position_Get = Player(ply):GetPosition()
				local FuelNozzleHash = natives.GAMEPLAY.GET_HASH_KEY("prop_cs_fuel_nozle")
				natives.STREAMING.REQUEST_MODEL(FuelNozzleHash)
				local FuelNozzle = natives.OBJECT.CREATE_OBJECT(FuelNozzleHash, 0, 0, 0, true, true, false)
				natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(FuelNozzle, plyPed, 0x49d9, -0.58, 0.45, -0.07, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
				if SpawnedFuelNozzle == nil then SpawnedFuelNozzle = {} end
				table.insert(SpawnedFuelNozzle, FuelNozzle)
				local FillFuelTankHash = natives.GAMEPLAY.GET_HASH_KEY("prop_ld_jerrycan_01")
				natives.STREAMING.REQUEST_MODEL(FillFuelTankHash)
				local FillFuelTank = natives.OBJECT.CREATE_OBJECT(FillFuelTankHash, 0, 0, 0, true, true, false)
				natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(FillFuelTank, plyPed, 0x49d9, -0.58, -0.20, -0.60, 0.0, 0.0, 180.0, false, false, false, false, 2, true)
				if SpawnedFillFuelTank == nil then SpawnedFillFuelTank = {} end
				table.insert(SpawnedFillFuelTank, FillFuelTank)
				local FuelHoseHash = natives.GAMEPLAY.GET_HASH_KEY("prop_cs_fuel_hose")
				natives.STREAMING.REQUEST_MODEL(FuelHoseHash)
				local FuelHose = natives.OBJECT.CREATE_OBJECT(FuelHoseHash, 0, 0, 0, true, true, false)
				natives.ENTITY.ATTACH_ENTITY_TO_ENTITY(FuelHose, plyPed, 0x49d9, -0.58, 0.45, -0.09, 45.0, 0.0, 180.0, false, false, false, false, 2, true)
				if SpawnedFuelHose == nil then SpawnedFuelHose = {} end
				table.insert(SpawnedFuelHose, FuelHose)
			end
		end
			
			
		if IsKeyDown(StopRefuelStanceKey) then
			if AnimCheck3 == true then
				if SpawnedFuelNozzle ~= nil then
					for k,v in pairs(SpawnedFuelNozzle) do
						c_nozzle = CMemoryBlock(4)
						c_nozzle:WriteDWORD32(0, v)
						natives.ENTITY.DELETE_ENTITY(c_nozzle) 
						c_nozzle:Release()
						natives.AI.CLEAR_PED_TASKS_IMMEDIATELY(plyPed)
						VehicleFuelLevel = 0.1000
						gui.NotifyAboveMap ("Vehicle has been refuelled.",1000)
						AnimCheck3 = false
					end
					SpawnedFuelNozzle = nil
				end
				if SpawnedFuelHose ~= nil then
					for k,v in pairs(SpawnedFuelHose) do
						c_hose = CMemoryBlock(4)
						c_hose:WriteDWORD32(0, v)
						natives.ENTITY.DELETE_ENTITY(c_hose) 
						c_hose:Release()
						end
						SpawnedFuelHose = nil
					end
				if SpawnedFillFuelTank ~= nil then
					for k,v in pairs(SpawnedFillFuelTank) do
						c_ftank = CMemoryBlock(4)
						c_ftank:WriteDWORD32(0, v)
						natives.ENTITY.DELETE_ENTITY(c_ftank) 
						c_ftank:Release()
					end
					SpawnedFillFuelTank = nil
				end
			end
		end
	end
		
		
		
		
		
	if VehicleRepairAction then
		if IsKeyDown(RepairStanceKey) then
			natives.AI.CLEAR_PED_TASKS_IMMEDIATELY(plyPed)
			natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_SIT_UPS@MALE@ENTER")
			if natives.STREAMING.HAS_ANIM_DICT_LOADED("AMB@WORLD_HUMAN_SIT_UPS@MALE@ENTER") == true then
				BeginLayingDownTime = natives.TIME.GET_CLOCK_MINUTES()
				SavedStartingTime = BeginLayingDownTime
				natives.AI.TASK_PLAY_ANIM(plyPed, "AMB@WORLD_HUMAN_SIT_UPS@MALE@ENTER", "enter", 8, -8, -1, 0, 0, false, false, true)
				AnimTransferHelper = true
				if AnimReady then
					AnimCheck = true
					AnimReady = false
				end
			end
		end
		if IsKeyDown(StopRepairStanceKey) then
			natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@EXIT")
			if natives.STREAMING.HAS_ANIM_DICT_LOADED("AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@EXIT") == true then		
				natives.AI.TASK_PLAY_ANIM(plyPed, "AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@EXIT", "exit_flee", 8, -8, -1, 0, 0, false, false, true)
				AnimCheck = false
				if SpawnedWrenchRepair ~= nil then
					for k,v in pairs(SpawnedWrenchRepair) do
						c_RWrench = CMemoryBlock(4)
						c_RWrench:WriteDWORD32(0, v)
						natives.ENTITY.DELETE_ENTITY(c_RWrench) 
						c_RWrench:Release()
					end
					SpawnedWrenchRepair = nil
				end
				if SpawnedToolboxRepair ~= nil then
					for k,v in pairs(SpawnedToolboxRepair) do
						c_RToolbox = CMemoryBlock(4)
						c_RToolbox:WriteDWORD32(0, v)
						natives.ENTITY.DELETE_ENTITY(c_RToolbox) 
						c_RToolbox:Release()
					end
					SpawnedToolboxRepair = nil
				end
				if SpawnedScrewdriverRepair ~= nil then
					for k,v in pairs(SpawnedScrewdriverRepair) do
						c_RScrewdriver = CMemoryBlock(4)
						c_RScrewdriver:WriteDWORD32(0, v)
						natives.ENTITY.DELETE_ENTITY(c_RScrewdriver) 
						c_RScrewdriver:Release()
					end
					SpawnedScrewdriverRepair = nil
				end
			end
		end
		if IsKeyDown(VehicleRepairKey) then
			if LocalPlayer():IsInVehicle() then	
			else
				if natives.STREAMING.HAS_ANIM_DICT_LOADED("AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@BASE") == true then
					if AnimCheck == true then
						vehz = natives.PLAYER.GET_PLAYERS_LAST_VEHICLE()
						natives.VEHICLE.SET_VEHICLE_PETROL_TANK_HEALTH(vehz, 1000)
						natives.VEHICLE.SET_VEHICLE_ENGINE_HEALTH(vehz, 1000)
						natives.ENTITY.SET_ENTITY_HEALTH(vehz, 1000)
						natives.VEHICLE.SET_VEHICLE_FIXED(vehz)
						gui.NotifyAboveMap ("Vehicle repaired",1000)
					end
				end
			end
		end
	end
	
	
	
	
	
	
	if PlayerSitBench then
		if LocalPlayer():IsInVehicle() then	
		else
			if SitHelperBench then
				FinishedTimeAnim = natives.TIME.GET_CLOCK_MINUTES()
				if FinishedTimeAnim-3.2 > SavedStartingTime then
					natives.STREAMING.REQUEST_ANIM_DICT("SAFE@MICHAEL@IG_3")
					natives.STREAMING.REQUEST_ANIM_DICT("SAFE@MICHAEL@IG_3")
					natives.AI.TASK_PLAY_ANIM(plyPed, "SAFE@MICHAEL@IG_3", "tv_base_michael", 8, -8, -1, 1, 0, false, false, true)
					AnimTransitionHelper = true
					SitHelperBench = false
				end
			end
			if IsKeyDown(SitBenchDownKey) then
				natives.STREAMING.REQUEST_ANIM_DICT("SAFE@MICHAEL@IG_3")
				natives.STREAMING.REQUEST_ANIM_DICT("SAFE@MICHAEL@IG_3")
				natives.AI.TASK_PLAY_ANIM(plyPed, "SAFE@MICHAEL@IG_3", "enter_michael", 8, -8, -1, 0, 0, false, false, true)
				BeginLayingDownTime = natives.TIME.GET_CLOCK_MINUTES()
				SavedStartingTime = BeginLayingDownTime
				FinishedTimeAnim = natives.TIME.GET_CLOCK_MINUTES()
				SitHelperBench = true
			end
			if IsKeyDown(StandUpBenchKey) then
				natives.STREAMING.REQUEST_ANIM_DICT("SAFE@MICHAEL@IG_3")
				natives.STREAMING.REQUEST_ANIM_DICT("SAFE@MICHAEL@IG_3")
				natives.AI.TASK_PLAY_ANIM(plyPed, "SAFE@MICHAEL@IG_3", "exit_michael", 8, -8, -1, 0, 0, false, false, true)
			end
		end
	end

	if PlayerSitGround then
		if LocalPlayer():IsInVehicle() then	
		else
			if SitHelperGround then
				FinishedTimeAnim = natives.TIME.GET_CLOCK_MINUTES()
				if FinishedTimeAnim-1.2 > SavedStartingTime then
					natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@IDLE_A")
					natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@IDLE_A")
					natives.AI.TASK_PLAY_ANIM(plyPed, "AMB@WORLD_HUMAN_STUPOR@MALE@IDLE_A", "idle_c", 8, -8, -1, 1, 0, false, false, true)
					AnimTransitionHelper = true
					SitHelperGround = false
				end
			end
			if IsKeyDown(SitGroundDownKey) then
				natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@BASE")
				natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@BASE")
				natives.AI.TASK_PLAY_ANIM(plyPed, "AMB@WORLD_HUMAN_STUPOR@MALE@BASE", "base", 8, -8, -1, 0, 0, false, false, true)
				BeginLayingDownTime = natives.TIME.GET_CLOCK_MINUTES()
				SavedStartingTime = BeginLayingDownTime
				FinishedTimeAnim = natives.TIME.GET_CLOCK_MINUTES()
				SitHelperGround = true
			end
			if IsKeyDown(StandUpGroundKey) then
				natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@EXIT")
				natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@EXIT")
				natives.AI.TASK_PLAY_ANIM(plyPed, "AMB@WORLD_HUMAN_STUPOR@MALE@EXIT", "exit_flee", 8, -8, -1, 0, 0, false, false, true)
			end
		end
	end
end




-- AnimatedActions init
function Animated_Actions.init()
	CurrentDirtLevel = 0

	SitAnywhereOn = false
	SitOnGround = false
	AnimTransitionHelper = false
	AnimTransferHelper = false
	VehicleRepairAction = false
	VehicleCleanAction = false
	VehicleRefuelAction = false
	PlayerSitGround = false
	PlayerSitBench = false
	AnimReady = false
	AnimCheck2 = false
	AnimCheck3 = false
	natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@EXIT")
	natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@BASE")
	natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_STUPOR@MALE@IDLE_A")
	natives.STREAMING.REQUEST_ANIM_DICT("SAFE@MICHAEL@IG_3")
	natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@EXIT")
	natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_SIT_UPS@MALE@ENTER")
	natives.STREAMING.REQUEST_ANIM_DICT("TIMETABLE@GARDENER@FILLING_CAN")
	natives.STREAMING.REQUEST_ANIM_DICT("TIMETABLE@FLOYD@CLEAN_KITCHEN@IDLE_A")
	natives.STREAMING.REQUEST_ANIM_DICT("TIMETABLE@FLOYD@CLEAN_KITCHEN@BASE")
	natives.STREAMING.REQUEST_ANIM_DICT("AMB@WORLD_HUMAN_VEHICLE_MECHANIC@MALE@BASE")

end

-- AnimatedActions Onerror 
function Animated_Actions:OnError()
	--self:Kill()
	--addon.Load("RENAMEME")
end